<template>
<view>
<!-- 	<view class="button-container">
		<input type="text" auto-focus="true" @input="checkInputLength" class="black-border-input" v-model="inputValue"/>
		<button @click="shoudong">手动输入</button>
	</view> -->
	<view class="container">
		<view class="info-card">
			<input type="text" auto-focus="true" @input="checkInputLength" class="black-border-input" v-model="inputValue"/>
		</view> 
	</view>
	<view class="button-container1">
		<button @click="shoudong">扫描随货同行单</button>
		<button @click="goback">返回</button>
	</view>
</view>
</template>

<script> 
import { ref } from 'vue'

export default {
  data() {
		return {
		 inputValue: '' ,// 添加一个数据属性来存储输入框的值
		output: '',
		purchaseinorderResult: {}
		  
		};
  },
  onLoad() {
    // this.startScan(); 
  },
  methods: {
	  checkInputLength(event) {
	    if (event.target.value.length > 10) {
			const inputValue = event.target.value;
			console.log('输入框的值:', inputValue); 
			this.handleScanResult(inputValue);
	  	  //扫描后逻辑
	      this.output = inputValue;
	    } else {
	      this.output = '';
	    }
	  },
	      shoudong(){
      // 弹出手动输入的模态对话框
      uni.showModal({
        title: '手动输入',
        content: '',
        placeholderText: '请输入内容',
        editable: true, // 允许输入
        success: (res) => {
          if (res.confirm) {
            // 用户点击确定按钮，获取输入的内容
            const userInput = res.content;
            this.inputValue = userInput; // 将输入的内容赋值到 inputValue
            this.checkInputLength({ target: { value: userInput } }); // 调用 checkInputLength 方法
          }
        }
      })},
    
    startScan() {
      uni.scanCode({
        success: (res) => {
          this.handleScanResult(res.result);
        },
        fail: (err) => {
          console.error('扫描失败:', err);
          console.Console('扫描失败:', err);
        }
      });
    },

handleScanResult(scanData) {
  console.log('扫描结果', scanData);
  // 跳转暂时拿出来测试
  uni.navigateTo({
    url: `/pages/scanCode/login?data=${encodeURIComponent(scanData)}`
  });
},
async goback(){
	uni.navigateBack();
},



  },
};
</script>

<style>
.container {
  padding: 20px;
  background-color: #f5f5f5;
}

.info-card {
  background-color: #ffffff;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 15px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.info-card.horizontal {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
}

.item-field {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.label {
  font-size: 15px;
  color: #333333;
  margin-bottom: 5px;
}

.value {
  font-size: 13px;
  color: #007aff;
}

.button-container {
  padding-top: 20px;
  text-align: center;
}

.button-container1 {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: #ffffff;
  padding: 5px 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  text-align: center;
}
button {
  margin: 5px 5px;
}
</style>